import { useState } from 'react';
import { createModel } from 'hox';
import {userInfo} from "../services/Login";

function useCounter() {
  const [userInfo, setUserInfo] = useState(JSON.parse(sessionStorage.getItem('detail')) || {});

  const saveUserInfo = (nk, pt, uid) =>
    setUserInfo((s) => {
      sessionStorage.setItem('detail', JSON.stringify({ ...s, nk, pt, uid }));
      return { ...s, nk, pt, uid };
    });

  return {
    userInfo,
    saveUserInfo,
  };
}

export default createModel(useCounter);
